package com.qjdchina.sku.biz.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qjdchina.commons.result.Result;
import com.qjdchina.sku.biz.RelProductSkuAttributeManager;
import com.qjdchina.sku.dao.mapper.RelProductSkuAttributeMapper;
import com.qjdchina.sku.model.RelProductSkuAttribute;
import com.qjdchina.sku.service.enums.SkuResultCode;

@Service
public class RelProductSkuAttributeManagerImpl implements RelProductSkuAttributeManager{

	public static final Logger LOGGER = LoggerFactory.getLogger(RelProductSkuAttributeManagerImpl.class);
	@Autowired
	private RelProductSkuAttributeMapper relProductSkuAttributeMapper;
	/**
	 * 根据skuItemId查询
	 * shenpingfeng
	 * 2017年2月16日
	 * @param skuItemId
	 * @return
	 */
	@Override
	public Result<List<RelProductSkuAttribute>> getRelProductSkuAttributeBySkuItemId(Integer skuItemId) {
		if(skuItemId == null){
			return new Result<List<RelProductSkuAttribute>>(SkuResultCode.PARAMETER_NOT_EMPTY);
		}
		List<RelProductSkuAttribute> relProductSkuAttributes = relProductSkuAttributeMapper.selectBySkuItemId(skuItemId);
		if(relProductSkuAttributes == null || relProductSkuAttributes.size() == 0){
			return new Result<List<RelProductSkuAttribute>>(SkuResultCode.DATA_NOT_EXIST);
		}
		return new Result<List<RelProductSkuAttribute>>(relProductSkuAttributes);
	}
	
	/**
     * 根据skuItemId和value获取
     * shenpingfeng
     * 2017年2月22日
     * @param skuItemId
     * @param value
     * @return
     */
	@Override
	public Result<List<RelProductSkuAttribute>> getRelProductSkuAttributeBySkuItemIdAndValue(Integer skuItemId,String value) {
		if(skuItemId == null || StringUtils.isBlank(value)){
			return new Result<List<RelProductSkuAttribute>>(SkuResultCode.PARAMETER_NOT_EMPTY);
		}
		List<RelProductSkuAttribute> relProductSkuAttributes = relProductSkuAttributeMapper.selectBySkuItemIdAndValue(skuItemId, value);
		if(relProductSkuAttributes == null || relProductSkuAttributes.size() == 0){
			return new Result<List<RelProductSkuAttribute>>(SkuResultCode.DATA_NOT_EXIST);
		}
		return new Result<List<RelProductSkuAttribute>>(relProductSkuAttributes);
	}

	
	
}
